//
//  Home_ZP_02TableViewCell.m
//  MagicBox
//
//  Created by dllo on 16/8/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Home_ZP_02TableViewCell.h"
#import "Home_ZP_02CollectionViewCell.h"
#import "HomePage_WebViewController.h"
@interface Home_ZP_02TableViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) NSMutableArray *muarray;
@end


@implementation Home_ZP_02TableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
        self.muarray = [NSMutableArray array];
        
        
    }
    return self;
}

-(void)setOnedic:(NSDictionary *)onedic{
    
    NSDictionary *dic = [onedic objectForKey:@"image_url"];

    [self.muarray addObject:dic];


}
-(void)setTwodic:(NSDictionary *)twodic{
    NSDictionary *dic = [twodic objectForKey:@"image_url"];
    [self.muarray addObject:dic];
    
    [self creactCollection];
}
-(void)creactCollection{

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(SCREENWIDTH/2-10,SCREENHEIGHT/6);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(5,0, SCREENWIDTH, SCREENHEIGHT/6) collectionViewLayout:layout];
    self.collection.backgroundColor = [UIColor whiteColor];
    
    self.collection.dataSource =self;
    self.collection. delegate = self;

    [self.contentView addSubview:self.collection];
    [self.collection registerClass:[Home_ZP_02CollectionViewCell class] forCellWithReuseIdentifier:@"oneCell"];
    
    
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  
    return 2;
    
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    Home_ZP_02CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"oneCell" forIndexPath:indexPath];

    cell.imagestring = [self.muarray objectAtIndex:indexPath.row];
    
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 ) {
        
    
    HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
    hwvc.urlStr = @"http://platform.58.com/city/getData?os=android";
    [[self naviController]pushViewController:hwvc animated:YES];
    }else{
        HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
        hwvc.urlStr = @"http://topic.m.58che.com/topic/1890topic.html?from=58tc.000104&os=android";
        [[self naviController]pushViewController:hwvc animated:YES];
    }
    
}




- (UINavigationController*)naviController {
    
    for (UIView* next = [self superview]; next; next = next.superview) {
        
        UIResponder* nextResponder = [next nextResponder];
        
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            
            return (UINavigationController*)nextResponder;
        }
    }
    return nil;
}
@end
